package isp.apps.example.shoppingcart.persistence.hibernate;

import isp.apps.example.shoppingcart.domain.CartItem;
import isp.apps.example.shoppingcart.domain.CompletedOrder;
import isp.apps.example.shoppingcart.domain.ShippingOption;
import isp.apps.example.shoppingcart.persistence.CompletedOrderDirectory;

import isp.apps.example.shoppingcart.persistence.OrderStatusDirectory;
import isp.apps.example.shoppingcart.persistence.PersistenceManagerFactory;

import isp.apps.example.shoppingcart.persistence.ShippingOptionsDirectory;
import isp.apps.example.shoppingcart.persistence.factory.OrderStatusPersistenceFactory;

import isp.apps.example.shoppingcart.persistence.factory.ShippingOptionsPersistenceFactory;

import isp.utils.cjis.persistence.PersistenceException;
import isp.utils.cjis.persistence.PersistenceManager;

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class HibernateCompletedOrderDirectory
  implements CompletedOrderDirectory
{
  private PersistenceManager persistenceManager =
    PersistenceManagerFactory.getPersistenceManager();

  private static final Log log =
    LogFactory.getLog(HibernateCompletedOrderDirectory.class);

  public HibernateCompletedOrderDirectory()
  {
  }

  public CompletedOrder getOrderById(Integer orderId)
  {
    try
    {
      CompletedOrder co = (CompletedOrder)persistenceManager.load(CompletedOrder.class, orderId);
      return co;
    }
    catch (PersistenceException pe)
    {
      log.error(pe, pe);
      return null;
    }
  }
  
  public List getOrders()
  {
    try
    {
      return persistenceManager.find("get.completedOrder", Collections.EMPTY_LIST);
    }
    catch (PersistenceException pe)
    {
      log.error(pe, pe);
      return null;
    }
  }
  
  
  public List getIncompleteOrders()
  {
    try
    {
    
      return persistenceManager.find("get.incompleteOrders", Collections.EMPTY_LIST);
 
    }
    catch (PersistenceException pe)
    {
      log.error(pe, pe);
      return null;
    }
  }
  
}
